
var questionCount=0;
var temporaryDataCount=0;

function fetchStudentDetails(){
	
	
	var cedullaValue = $("#cedulla").val();
	if(cedullaValue==""){alert("Please enter a value for cedulla.");}
	else{
	
	$.ajax({ 
	    url: "spring/fetchUserDetails", 
	    type: 'POST', 
	    dataType: 'json', 
	    data: "{\"cedulla\":"+cedullaValue+"}", 
	    contentType: 'application/json',
	    mimeType: 'application/json',
	    success: function(data) { 
	        //alert(data.studentName + " " + data.cedulla);
	    	
	    	if(data.cedulla==""){
	    		$("#searchResult").html("Cedulla not found !!");
	    		$("#cedullaDetailsTable").css("display","none");
	    		$("#searchResult").css("display","inline");
	    		}
	    	else{
	    	$("#searchResult").css("display","none");
	    	$("#cedullaDetailsTable").css("display","inline");
	    	$("#cedullaValue").html(data.cedulla);
	    	$("#userName").html(data.userName);
	    	$("#userType").html(data.userType);
	    	if(data.currentSemester==null || data.currentSemester=="" || data.currentSemester=="0" || data.currentSemester==0){$("#currentSemester").html("NA");}
	    	else{$("#currentSemester").html(data.currentSemester);}
	    	
	    	$("#departmentName").html(data.department);
	    	
	    	if(data.surveyComplete == 0){$("#surveyComplete").html("<a href='spring/survey/"+cedullaValue+"'>START SURVEY !!</a>");$("#surveyComplete").css("color","#088A29");$("#surveyStatus").html("INCOMPLETE");$("#surveyStatus").css("background-color","red");}
	    	else{$("#surveyComplete").html("SURVEY COMPLETE !!");$("#surveyComplete").css("color","#FF4000");$("#surveyStatus").html("COMPLETE");$("#surveyStatus").css("background-color","lime");}
	    	
	    	}
	    },
	    error:function(data,status,er) { 
	        alert("error: "+data+" status: "+status+" er:"+er);
	    }
	});
	
}
	
/*	$(function() {
		$.post("spring/fetchStudentDetails", {
			cedulla : cedullaValue
		}, function(data) {
	alert(data);
		});

	});*/
		
};


function populateQuestions(url,activePanel,cedulla,currentSemester,userType){
	
	
	if(currentSemester==""){currentSemester=-1;}
	
	var activeTable="table#table-"+activePanel;
	
	var currentRowCount = $(activeTable+" tr").length;
	
	if(currentRowCount==3){
	
	var activeAnchor="a[href$='#tabs-"+activePanel+"']";
	
	var subjectId=$(activeAnchor).parent().attr("id");

	
	$.ajax({ 
	    url: url, 
	    type: 'POST', 
	    dataType: 'json', 
	    data: "{\"cedulla\":"+cedulla +",\"subject\":"+subjectId +",\"currentSemester\":"+currentSemester +",\"userType\": \""+userType+"\"}", 
	    contentType: 'application/json',
	    mimeType: 'application/json',
	    success: function(data) { 
	        //alert(data);
	        
	        $.each(data, function(index) {
	        	
	        	
	        		        	
	        	var htmlString = 	        		
	        	'<tr style="background-color: #D8D8D8;font-size: 12px; font-family: calibri sans serif palatino linotype;" >'+
				'<td align="center" width="5%">'+(index+1)+'</td>'+
				'<td width="30%"><p>'+data[index].questionString+'</p></td>'+
				'<td width="65%">'+
					'<table width="100%">'+
						'<tr >'+
							'<th width="25%"><input type="radio" class="x"  name="questions['+questionCount+'].rating" value="1" /></th>'+
							'<th width="25%"><input type="radio" class="x" name="questions['+questionCount+'].rating" value="2" /></th>'+
							'<th width="25%"><input type="radio" class="x" name="questions['+questionCount+'].rating" value="3" /></th>'+
							'<th width="25%"><input type="radio" class="x" name="questions['+questionCount+'].rating" value="4" /></th>'+
						'</tr>'+
					'</table> <input name="questions['+questionCount+'].questionId"	value="'+data[index].questionId+'" class="hiddenField"> '+
	        		'<input name="questions['+questionCount+'].subjectId" value="'+data[index].subjectId+'" class="hiddenField">'+
				'</td>'+
				'</tr>';
	        	
	        	
	        	
	        	
	        	//alert(htmlString);
			
	        	$(activeTable).append(htmlString);
	        	//$(activeTable).table("refresh");
	        	
	        	questionCount = questionCount+1;
	        });
	        
	        
	    	
	    	/*if(data.cedulla==""){
	    		$("#searchResult").html("Cedulla not found !!");
	    		$("#cedullaDetailsTable").css("display","none");
	    		$("#searchResult").css("display","inline");
	    		}
	    	else{
	    	$("#searchResult").css("display","none");
	    	$("#cedullaDetailsTable").css("display","inline");
	    	$("#cedullaValue").html(data.cedulla);
	    	$("#userName").html(data.userName);
	    	$("#userType").html(data.userType);
	    	$("#currentSemester").html(data.currentSemester);
	    	$("#departmentName").html(data.department);
	    	
	    	if(data.surveyComplete == 0){$("#surveyComplete").html("<a href='spring/survey/"+cedullaValue+"'>START SURVEY !!</a>");$("#surveyComplete").css("color","#088A29");$("#surveyStatus").html("INCOMPLETE");$("#surveyStatus").css("background-color","red");}
	    	else{$("#surveyComplete").html("SURVEY COMPLETE !!");$("#surveyComplete").css("color","#FF4000");$("#surveyStatus").html("COMPLETE");$("#surveyStatus").css("background-color","lime");}
	    	
	    	}*/
	    },
	    error:function(data,status,er) { 
	        alert("error: "+data+" status: "+status+" er:"+er);
	    }
	});
	
};
	
};